{
    "cells": [
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "<img src=\".+\\\\diyLogo.png\" alt=\"some_text\">\n",
                "<h1> 第一讲 基本数据结构</h1>\n",
                "<a id=backup></a>\n",
                "<H2>目录</H2>  \n",
                "\n",
                "[1.1 数字常量](#Literals)   \n",
                "[1.2 标准数据类型](#data_type)   \n",
                "[1.3 数字类型的操作](#num_opr)   \n",
                "[1.4 字符串](#char_opr)   \n",
                "[1.5 Latex数学公式编辑](#Latex_form)   \n",
                "\n"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "<a id=\"Literals\"></a>\n",
                "### 1.1 数字常量\n",
                "\n",
                "Python3 支持 **int、float、bool、complex**（复数）。\n",
                "\n",
                "在Python 3里，只有一种整数类型 **int**，表示为长整型，没有 python2 中的 **Long**。\n",
                "\n",
                "像大多数语言一样，数值类型的赋值和计算都是很直观的。\n",
                "\n",
                "内置的 type() 函数可以用来查询变量所指的对象类型。\n"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "试执行下列语句：   \n",
                "`z=2+5j`   \n",
                "`type(z)`    \n",
                "`print(z.conjugate())`"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 4,
            "metadata": {},
            "outputs": [
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": [
                        "(2-5j)\n"
                    ]
                }
            ],
            "source": [
                "###\n",
                "z=2+5j  \n",
                "type(z)\n",
                "print(z.conjugate())\n"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "与数学中的整数概念一致，没有取值范围限制\n",
                "pow(x, y)函数：\n",
                "计算 $ x^{y} $  \n",
                "`pow(2,600)`\n"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 15,
            "metadata": {},
            "outputs": [
                {
                    "data": {
                        "text/plain": [
                            "4149515568880992958512407863691161151012446232242436899995657329690652811412908146399707048947103794288197886611300789182395151075411775307886874834113963687061181803401509523685376"
                        ]
                    },
                    "execution_count": 15,
                    "metadata": {},
                    "output_type": "execute_result"
                }
            ],
            "source": [
                "###\n",
                "pow(2,600)\n"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 16,
            "metadata": {},
            "outputs": [
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": [
                        "sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)\n",
                        "sys.int_info(bits_per_digit=30, sizeof_digit=4)\n"
                    ]
                }
            ],
            "source": [
                "import sys\n",
                "print(sys.float_info)\n",
                "print(sys.int_info)\n"
            ]
        },
        {
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "<a id=\"data_type\"></a>\n",
                "## 1.2 标准数据类型\n",
                "<h3 style=\"color:green\"> Python3 中有六个标准的数据类型：</h3>\n",
                "  \n",
                "<table border=\"1\">\n",
                "    <tr>\n",
                "        <td> Number</td>\n",
                "        <td>数字</td>\n",
                "    </tr>\n",
                "    <tr>\n",
                "        <td>String</td>\n",
                "        <td>字符串</td>\n",
                "    </tr>\n",
                "    <tr>\n",
                "        <td>List</td>\n",
                "        <td>列表</td>\n",
                "    </tr>    \n",
                "    <tr>\n",
                "        <td>Tuple</td>\n",
                "        <td>元组</td>\n",
                "    </tr>    \n",
                "    <tr>\n",
                "        <td>Set</td>\n",
                "        <td>集合</td>\n",
                "    </tr>\n",
                "    <tr>\n",
                "        <td>Dictionary</td>\n",
                "        <td>字典</td>\n",
                "    </tr>\n",
                "</table>\n",
                "<h3 style=\"color:green\">Python3 的六个标准数据类型中：</h3>\n",
                "\n",
                "不可变数据（3 个）：Number（数字）、String（字符串）、Tuple（元组）；  \n",
                "可变数据（3 个）：List（列表）、Dictionary（字典）、Set（集合）。  \n",
                "\n",
                "[目录](#backup) "
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "试执行下列语句：   \n",
                "```\n",
                "counter = 100       # 整型变量\n",
                "miles = 1000.0      # 浮点型变量\n",
                "name = \"ru'n'oob\"   # 字符串\n",
                "name2='xauat\"edu\"'\n",
                "name3='''a \n",
                "b\n",
                " c '''\n",
                "list1  = [1, 2, 3, 4, 5] # 列表\n",
                "tup1 = (1, 2, 3, 4, 5)  # 元 组\n",
                "dict = {'name': '张三', 'age': 15, 'Mail': 'zhs@163.com'} # 字典\n",
                "basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'} # 集合\n",
                "print(counter)\n",
                "print(miles)\n",
                "print(name)\n",
                "print(basket)\n",
                "```"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 7,
            "metadata": {},
            "outputs": [
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": [
                        "100\n",
                        "1000.0\n",
                        "ru'n'oob\n",
                        "{'orange', 'apple', 'pear', 'banana'}\n"
                    ]
                }
            ],
            "source": [
                "###\n",
                "counter = 100       # 整型变量\n",
                "miles = 1000.0      # 浮点型变量\n",
                "name = \"ru'n'oob\"   # 字符串\n",
                "name2='xauat\"edu\"'\n",
                "name3='''a \n",
                "b\n",
                " c '''\n",
                "list1  = [1, 2, 3, 4, 5] # 列表\n",
                "tup1 = (1, 2, 3, 4, 5)  # 元 组\n",
                "dict = {'name': '王五', 'age': 15, 'Mail': 'zhs@163.com'} # 字典\n",
                "basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'} # 集合\n",
                "print(counter)\n",
                "print(miles)\n",
                "print(name)\n",
                "print(basket)"
            ]
        },
        {
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "<a id=\"num_opr\"></a>\n",
                "## 1.3 数字类型的操作\n",
                "数值计算+ - * /\n",
                "\n",
                "[目录](#backup) "
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "试执行下列语句：   \n",
                "````\n",
                "a = b = 1\n",
                "c=a+b\n",
                "print(\"a+b=\", c)\n",
                "c=a*b\n",
                "print(\"a*b=\", c)\n",
                "a=8\n",
                "b=3\n",
                "c=a/b\n",
                "print(\"a/b=\", c)\n",
                "c=a//b\n",
                "print(\"a//b=\", c)\n",
                "c = a%b\n",
                "print(\"a%b =\", c)\n",
                "c = a ** b\n",
                "print(\"a**b=\", c)\n",
                "````"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 17,
            "metadata": {},
            "outputs": [
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": [
                        "a+b= 2\n",
                        "a*b= 1\n",
                        "a/b= 2.6666666666666665\n",
                        "a//b= 2\n",
                        "a%b = 2\n",
                        "a**b= 512\n"
                    ]
                }
            ],
            "source": [
                "###\n",
                "a = b = 1\n",
                "c=a+b\n",
                "print(\"a+b=\", c)\n",
                "c=a*b\n",
                "print(\"a*b=\", c)\n",
                "a=8\n",
                "b=3\n",
                "c=a/b\n",
                "print(\"a/b=\", c)\n",
                "c=a//b\n",
                "print(\"a//b=\", c)\n",
                "c = a%b\n",
                "print(\"a%b =\", c)\n",
                "c = a ** b\n",
                "print(\"a**b=\", c)"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "<a id=\"char_opr\"></a>\n",
                "## 1.4 字符串变量操作\n",
                "字符串是 Python 中最常用的数据类型。我们可以使用引号( ' 、 \" 或 ''')来创建字符串。\n",
                "\n",
                "创建字符串很简单，只要为变量分配一个值即可。例如：\n",
                "\n",
                "[目录](#backup) "
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "试执行下列语句：   \n",
                "\n",
                "var1 = 'Hello World!'\n",
                "var2 = \"Runoob\"\n",
                "var3='''He````llo World '''\n",
                "````"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 1,
            "metadata": {},
            "outputs": [],
            "source": [
                "###\n",
                "\n",
                "var1 = 'Hello World!'\n",
                "var2 = \"Runoob\"\n",
                "var3='''He````llo World '''\n"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "Python 访问字符串中的值\n",
                "Python 不支持单字符类型，单字符在 Python 中也是作为一个字符串使用。\n",
                "\n",
                "Python 访问子字符串，可以使用方括号 [] 来截取字符串，字符串的截取的语法格式如下：\n",
                "`print(var1[1:5])'"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 2,
            "metadata": {},
            "outputs": [
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": [
                        "ello\n"
                    ]
                }
            ],
            "source": [
                "###\n",
                "print(var1[1:5])"
            ]
        },
        {
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "\n",
                "[目录](#backup) "
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "<a id=\"Latex_form\"></a>\n",
                "## 1.5 Latex数学公式编辑\n",
                "在jupyter notebook使用latex编辑数学公式\n",
                "使用下划线_表示下标，使用^表示上标: $X={\\ x}^{a} \n",
                "d\\varPsi = \\int_{a}^{b} \\ x_i \\,d\\alpha $\n",
                "\n",
                "[目录](#backup) "
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$x_{(22)}^{(n)}\\qquad$"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$x_{(22)}^{(n)}\\qquad$"
            ]
        },
        {
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\frac{1}{1+\\frac{1}{2}}\\qquad$"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\frac{1}{1+\\frac{1}{2}}\\qquad$"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\sqrt{1+\\sqrt[^p]{1+a^2}}\\qquad$"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\sqrt{1+\\sqrt[^p]{1+a^2}}\\qquad$"
            ]
        },
        {
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\int_1^\\infty\\qquad$"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\int_1^\\infty\\qquad$"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\sum_{k=1}^n\\frac{1}{k}\\qquad $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\sum_{k=1}^n\\frac{1}{k}\\qquad $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\int_a^b f(x)dx\\qquad$"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\int_a^b f(x)dx\\qquad$"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\frac{\\partial E_w}{\\partial w}\\qquad $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\frac{\\partial E_w}{\\partial w}\\qquad $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\lim_{1\\to\\infty}\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\lim_{1\\to\\infty}\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\lt \\gt \\le \\ge \\neq \\not\\lt \\neq\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\lt \\gt \\le \\ge \\neq \\not\\lt \\neq\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\times \\div \\pm \\mp x \\cdot y\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\times \\div \\pm \\mp x \\cdot y\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\cup \\cap \\setminus \\subset \\subseteq \\subsetneq \\supset \\in \\notin \\emptyset   \\varnothing\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\cup \\cap \\setminus \\subset \\subseteq \\subsetneq \\supset \\in \\notin \\emptyset   \\varnothing\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\to \\rightarrow \\leftarrow \\Rightarrow \\Leftarrow \\mapsto\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\to \\rightarrow \\leftarrow \\Rightarrow \\Leftarrow \\mapsto\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\land \\lor \\lnot \\forall \\exists \\top \\bot \\vdash \\vDash\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\land \\lor \\lnot \\forall \\exists \\top \\bot \\vdash \\vDash\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\star \\ast \\oplus \\circ \\bullet\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\star \\ast \\oplus \\circ \\bullet\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\approx \\sim \\cong \\equiv \\prec\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\approx \\sim \\cong \\equiv \\prec\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\infty \\aleph \\nabla \\partial\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\infty \\aleph \\nabla \\partial\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\epsilon \\varepsilon\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\epsilon \\varepsilon\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\phi \\varphi\\qquad $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\left \\lbrace \\sum_{i=0}^n i^2 = \\frac{(n^2+n)(2n+1)}{6} \\right\\rbrace \\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\left \\lbrace \\sum_{i=0}^n i^2 = \\frac{(n^2+n)(2n+1)}{6} \\right\\rbrace \\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\left( \\sum_{k=\\frac{1}{2}}^{N^2}\\frac{1}{k} \\right)\\qquad $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\left( \\sum_{k=\\frac{1}{2}}^{N^2}\\frac{1}{k} \\right)\\qquad $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\left. \\frac{\\partial f(x, y)}{\\partial x}\\right|_{x=0}\\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\left\\lbrace\\begin{aligned}a\\\\b\\\\c\\\\\\end{aligned}\\right\\rbrace \\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\left\\lbrace\\begin{aligned}a\\\\b\\\\c\\\\\\end{aligned}\\right\\rbrace \\qquad  $"
            ]
        },
        {
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$\\left\\lbrace\\begin{aligned}a\\\\b\\\\c\\\\\\end{aligned}\\right\\rbrace \\qquad  $"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$$\\left\\lbrace\\begin{aligned}  \n",
                "a_1x+b_1y+c_1z &=d_1+e_1 \\\\\\ \n",
                "a_2x+b_2y &=d_2 \\\\\\ \n",
                "a_3x+b_3y+c_3z &=d_3\n",
                "\\end{aligned}\\right\\rbrace \\qquad  $$\n"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "$$\\left\\lbrace\\begin{aligned}  \n",
                "a_1x+b_1y+c_1z &=d_1+e_1 \\\\\\ \n",
                "a_2x+b_2y &=d_2 \\\\\\ \n",
                "a_3x+b_3y+c_3z &=d_3\n",
                "\\end{aligned}\\right\\rbrace \\qquad  $$"
            ]
        },
        {
            "attachments": {},
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "### 数值类型实例"
            ]
        },
        {
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "<table><tr><th>int</th><th>long</th><th>float</th><th>complex</th></tr>\n",
                "<tr><td>10</td><td>51924361L</td><td>0.0</td><td>3.14j</td></tr>\n",
                "<tr><td>100</td><td>-0x19323L</td><td>15.20</td><td>45.j</td></tr>\n",
                "<tr><td>-786</td><td>0122L</td><td>-21.9</td><td>9.322e-36j</td></tr>\n",
                "<tr><td>080</td><td>0xDEFABCECBDAECBFBAEl</td><td>32.3e+18</td><td>.876j</td></tr>\n",
                "<tr><td>-0490</td><td>535633629843L</td><td>-90.</td><td>-.6545+0J</td></tr>\n",
                "<tr><td>-0x260</td><td>-052318172735L</td><td>-32.54e100</td><td>3e+26J</td></tr>\n",
                "<tr><td>0x69</td><td>-4721885298529L</td><td>70.2E-12</td><td>4.53e-7j</td></tr>\n",
                "</table>"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 1,
            "metadata": {},
            "outputs": [
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": [
                        "Hello World!\n"
                    ]
                }
            ],
            "source": [
                "# -*- coding: UTF-8 -*-\n",
                "\n",
                "# Filename : helloworld.py\n",
                "# author by : www.runoob.com\n",
                "\n",
                "# 该实例输出 Hello World!\n",
                "print('Hello World!')"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 5,
            "metadata": {},
            "outputs": [
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": [
                        "数字 9 和 90 相加结果为： 99.0\n"
                    ]
                }
            ],
            "source": [
                "   # -*- coding: UTF-8 -*-\n",
                "\n",
                " \n",
                "\n",
                "# 用户输入数字\n",
                "\n",
                "num1 = input('输入第一个数字：')\n",
                "\n",
                "num2 = input('输入第二个数字：')\n",
                "\n",
                "  \n",
                "\n",
                "# 求和\n",
                "\n",
                "sum = float(num1) + float(num2)\n",
                "\n",
                "  \n",
                "\n",
                "# 显示计算结果\n",
                "\n",
                "print('数字 {0} 和 {1} 相加结果为： {2}'.format(num1, num2, sum))      \n",
                "\n",
                "\n",
                " \n"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 5,
            "metadata": {},
            "outputs": [
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": [
                        " 9.000 的平方根为 3.000\n"
                    ]
                }
            ],
            "source": [
                "num = float(input('请输入一个数字： '))\n",
                "num_sqrt = num ** 0.5\n",
                "print(' %0.3f 的平方根为 %0.3f'%(num ,num_sqrt))"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 7,
            "metadata": {},
            "outputs": [
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": [
                        "结果为 (-0.6666666666666666-1.1055415967851332j) 和 (-0.6666666666666666+1.1055415967851332j)\n"
                    ]
                }
            ],
            "source": [
                "import cmath\n",
                " \n",
                "a = float(input('输入 a: '))\n",
                "b = float(input('输入 b: '))\n",
                "c = float(input('输入 c: '))\n",
                " \n",
                "d = (b**2) - (4*a*c)\n",
                "sol1 = (-b-cmath.sqrt(d))/(2*a)\n",
                "sol2 = (-b+cmath.sqrt(d))/(2*a)\n",
                " \n",
                "print('结果为 {0} 和 {1}'.format(sol1,sol2))"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 12,
            "metadata": {},
            "outputs": [
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": [
                        "1238.0807728092702\n"
                    ]
                }
            ],
            "source": [
                "a = float(input('输入三角形第一边长: '))\n",
                "b = float(input('输入三角形第二边长: '))\n",
                "c = float(input('输入三角形第三边长: '))\n",
                "\n",
                "s = (a + b + c) / 2\n",
                " \n",
                "area = (s*(s-a)*(s-b)*(s-c)) ** 0.5\n",
                "print(area)"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 15,
            "metadata": {},
            "outputs": [
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": [
                        "254.50199999999998\n"
                    ]
                }
            ],
            "source": [
                "def findArea(r):\n",
                "    PI = 3.142\n",
                "    return PI * (r*r)\n",
                " \n",
                "# 调用方法\n",
                "print( findArea(9))"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 13,
            "metadata": {},
            "outputs": [
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": [
                        "9292\n"
                    ]
                }
            ],
            "source": [
                "import random\n",
                " \n",
                "print(random.randint(0,10000))"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 9,
            "metadata": {},
            "outputs": [
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": [
                        "565.0 摄氏温度转为华氏温度为 1049.0 \n"
                    ]
                }
            ],
            "source": [
                "celsius = float(565)\n",
                "fahrenheit = (celsius * 1.8) + 32\n",
                "print('%0.1f 摄氏温度转为华氏温度为 %0.1f ' %(celsius,fahrenheit))"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 10,
            "metadata": {},
            "outputs": [
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": [
                        "234567156165165\n",
                        "98744651651\n"
                    ]
                }
            ],
            "source": [
                "x = 98744651651\n",
                "y = 234567156165165\n",
                "temp = x\n",
                "x = y\n",
                "y = temp\n",
                " \n",
                "print(format(x))\n",
                "print(format(y))"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 11,
            "metadata": {},
            "outputs": [
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": [
                        "2528 是闰年\n"
                    ]
                }
            ],
            "source": [
                "year = int(input(\"输入一个年份: \"))\n",
                "if (year % 4) == 0:\n",
                "   if (year % 100) == 0:\n",
                "       if (year % 400) == 0:\n",
                "           print(\"{0} 是闰年\".format(year))  \n",
                "           print(\"{0} 不是闰年\".format(year))\n",
                "   else:\n",
                "       print(\"{0} 是闰年\".format(year))      \n",
                "else:\n",
                "   print(\"{0} 不是闰年\".format(year))"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 17,
            "metadata": {},
            "outputs": [
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": [
                        "79\n",
                        "83\n",
                        "89\n",
                        "97\n",
                        "101\n",
                        "103\n",
                        "107\n",
                        "109\n",
                        "113\n",
                        "127\n",
                        "131\n",
                        "137\n",
                        "139\n",
                        "149\n",
                        "151\n",
                        "157\n",
                        "163\n",
                        "167\n",
                        "173\n",
                        "179\n",
                        "181\n",
                        "191\n",
                        "193\n",
                        "197\n",
                        "199\n",
                        "211\n",
                        "223\n",
                        "227\n",
                        "229\n",
                        "233\n",
                        "239\n",
                        "241\n",
                        "251\n",
                        "257\n",
                        "263\n",
                        "269\n",
                        "271\n",
                        "277\n",
                        "281\n",
                        "283\n",
                        "293\n",
                        "307\n",
                        "311\n",
                        "313\n",
                        "317\n",
                        "331\n",
                        "337\n",
                        "347\n",
                        "349\n",
                        "353\n",
                        "359\n",
                        "367\n",
                        "373\n",
                        "379\n",
                        "383\n",
                        "389\n",
                        "397\n",
                        "401\n",
                        "409\n",
                        "419\n",
                        "421\n",
                        "431\n",
                        "433\n",
                        "439\n",
                        "443\n",
                        "449\n",
                        "457\n",
                        "461\n",
                        "463\n",
                        "467\n",
                        "479\n",
                        "487\n",
                        "491\n",
                        "499\n",
                        "503\n",
                        "509\n",
                        "521\n",
                        "523\n",
                        "541\n",
                        "547\n",
                        "557\n",
                        "563\n",
                        "569\n",
                        "571\n",
                        "577\n",
                        "587\n",
                        "593\n",
                        "599\n",
                        "601\n"
                    ]
                }
            ],
            "source": [
                "#!/usr/bin/python3\n",
                " \n",
                "# 输出指定范围内的素数\n",
                " \n",
                "# take input from the user\n",
                "lower = int(input(\"输入区间最小值: \"))\n",
                "upper = int(input(\"输入区间最大值: \"))\n",
                " \n",
                "for num in range(lower,upper + 1):\n",
                "    # 素数大于 1\n",
                "    if num > 1:\n",
                "        for i in range(2,num):\n",
                "            if (num % i) == 0:\n",
                "                break\n",
                "        else:\n",
                "            print(num)"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 21,
            "metadata": {},
            "outputs": [
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": [
                        "FGVBHNGBVCDSCVDSGVCSDGCSDGCV\n",
                        "fgvbhngbvcdscvdsgvcsdgcsdgcv\n",
                        "Fgvbhngbvcdscvdsgvcsdgcsdgcv\n",
                        "Fgvbhngbvcdscvdsgvcsdgcsdgcv\n"
                    ]
                }
            ],
            "source": [
                "str = \"fgvbhngbvcdscvdsgvcsdgcsdgcv\"\n",
                "print(str.upper())          # 把所有字符中的小写字母转换成大写字母\n",
                "print(str.lower())          # 把所有字符中的大写字母转换成小写字母\n",
                "print(str.capitalize())     # 把第一个字母转化为大写字母，其余小写\n",
                "print(str.title())          # 把每个单词的第一个字母转化为大写，其余小写 "
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 22,
            "metadata": {},
            "outputs": [
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": [
                        "9号下船了\n",
                        "18号下船了\n",
                        "27号下船了\n",
                        "6号下船了\n",
                        "16号下船了\n",
                        "26号下船了\n",
                        "7号下船了\n",
                        "19号下船了\n",
                        "30号下船了\n",
                        "12号下船了\n",
                        "24号下船了\n",
                        "8号下船了\n",
                        "22号下船了\n",
                        "5号下船了\n",
                        "23号下船了\n"
                    ]
                }
            ],
            "source": [
                "people={}\n",
                "for x in range(1,31):\n",
                "    people[x]=1\n",
                "# print(people)\n",
                "check=0\n",
                "i=1\n",
                "j=0\n",
                "while i<=31:\n",
                "    if i == 31:\n",
                "        i=1\n",
                "    elif j == 15:\n",
                "        break\n",
                "    else:\n",
                "        if people[i] == 0:\n",
                "            i+=1\n",
                "            continue\n",
                "        else:\n",
                "            check+=1\n",
                "            if check == 9:\n",
                "                people[i]=0\n",
                "                check = 0\n",
                "                print(\"{}号下船了\".format(i))\n",
                "                j+=1\n",
                "            else:\n",
                "                i+=1\n",
                "                continue"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 24,
            "metadata": {},
            "outputs": [
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": [
                        "None\n",
                        "{'d': 6, 'c': 4, 'a': 532, 'b': 8}\n"
                    ]
                }
            ],
            "source": [
                "def Merge(dict1, dict2): \n",
                "    return(dict2.update(dict1)) \n",
                "      \n",
                "# 两个字典\n",
                "dict1 = {'a': 532, 'b': 8} \n",
                "dict2 = {'d': 6, 'c': 4} \n",
                "  \n",
                "# 返回  None \n",
                "print(Merge(dict1, dict2)) \n",
                "  \n",
                "# dict2 合并了 dict1\n",
                "print(dict2)"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 25,
            "metadata": {},
            "outputs": [
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": [
                        "字符数组排序 bcmnoooruwww\n"
                    ]
                }
            ],
            "source": [
                "def countSort(arr): \n",
                "  \n",
                "    output = [0 for i in range(256)] \n",
                "  \n",
                "    count = [0 for i in range(256)] \n",
                "  \n",
                "    ans = [\"\" for _ in arr] \n",
                "  \n",
                "    for i in arr: \n",
                "        count[ord(i)] += 1\n",
                "  \n",
                "    for i in range(256): \n",
                "        count[i] += count[i-1] \n",
                "  \n",
                "    for i in range(len(arr)): \n",
                "        output[count[ord(arr[i])]-1] = arr[i] \n",
                "        count[ord(arr[i])] -= 1\n",
                "  \n",
                "    for i in range(len(arr)): \n",
                "        ans[i] = output[i] \n",
                "    return ans  \n",
                "  \n",
                "arr = \"wwwrunoobcom\"\n",
                "ans = countSort(arr) \n",
                "print ( \"字符数组排序 %s\"  %(\"\".join(ans)) )"
            ]
        }
    ],
    "metadata": {
        "kernelspec": {
            "display_name": "Python 3.10.4 ('python310')",
            "language": "python",
            "name": "python3"
        },
        "language_info": {
            "codemirror_mode": {
                "name": "ipython",
                "version": 3
            },
            "file_extension": ".py",
            "mimetype": "text/x-python",
            "name": "python",
            "nbconvert_exporter": "python",
            "pygments_lexer": "ipython3",
            "version": "3.9.13"
        },
        "orig_nbformat": 4,
        "vscode": {
            "interpreter": {
                "hash": "a888cd810c90be07c3c921372a6d7ff433f5a38d5779dfb2a871d99db75673fb"
            }
        }
    },
    "nbformat": 4,
    "nbformat_minor": 2
}
